var first = document.querySelector('#number1'),
    second = document.querySelector('#number2'),
    result1 = document.querySelector('.result1');
if (!!window.SharedWorker) {
  var myWorker = new SharedWorker("worker.js",'sw1_');
  // 脚本通过messagePort对象来访问Worker，这个对象通过sharedWorker.port属性获得
  first.oninput = function() {
    myWorker.port.postMessage([first.value, second.value]);
    console.log('Message posted to worker');
  };
  second.oninput = function() {
    myWorker.port.postMessage([first.value, second.value]);
    console.log('Message posted to worker');
  };
  myWorker.port.onmessage = function(e) {
    result1.textContent = e.data;
    console.log('Message received from worker');
  };
}